<template>
	<div class="padding-across-10" v-loading.fullscreen.lock="loading" element-loading-text="拼命加载中">
		<div>
			<headerOpreate style="padding-bottom: 2px;float: left;margin-right: 10px" :opreate-datas="opreateDatas" v-on:executeAction="executeAction"></headerOpreate>
			<el-dropdown style="margin-top: 1px" split-button size="small" type="primary" @command="handleExportExcel">
				导出表格
				<el-dropdown-menu slot="dropdown">
					<el-dropdown-item command="1">
						<i class="el-icon-eleg-icon_table el-icon--left"></i>导出当前
					</el-dropdown-item>
					<el-dropdown-item command="2">
						<i class="el-icon-eleg-icon_table el-icon--left"></i>导出全部
					</el-dropdown-item>
				</el-dropdown-menu>
			</el-dropdown>
			<el-dropdown style="margin-top: 1px" split-button size="small" type="primary" @command="handleCommand">
				更多操作
				<el-dropdown-menu slot="dropdown">
					<el-dropdown-item command="1">
						<i class="el-icon-upload el-icon--left"></i>同步图书
					</el-dropdown-item>
					<el-dropdown-item command="2">
						<i class="el-icon-eleg-icon_cloud-download el-icon--left"></i>更新图书
					</el-dropdown-item>
					<el-dropdown-item command="3">
						<i class="el-icon-eleg-icon_cart el-icon--left"></i>剔旧列表
					</el-dropdown-item>
					<el-dropdown-item command="4">
						<i class="el-icon-eleg-icon_blocked el-icon--left"></i>图书剔旧
					</el-dropdown-item>
				</el-dropdown-menu>
			</el-dropdown>
		</div>
		<el-row style="width: 100%;padding-top: 5px;padding-bottom: 5px">
			<el-col :span="12">
				<div class="query" style="padding-top: 2px;display:inline">
					<div style="float: left">
						<span style="font-size: 13px;font-weight: bold">馆藏地</span>
						<el-select size="small" v-model="location" placeholder="暂无数据" style="width: 120px;margin-right: 2px" @change="selectLocation">
							<el-option v-for="item in locationDatas" :key="item.LocationKeyId" :label="item.Name" :value="item.LocationKeyId">
							</el-option>
						</el-select>
					</div>
					<div style="padding-left: 3px">
						<span style="font-size: 13px;font-weight: bold">检索字段</span>
						<el-select size="small" v-model="value" :placeholder="$t('message.selectModeAlert')" style="width: 90px;margin-right: 2px" @change="selectType">
							<el-option label="关键字" :value="0"></el-option>
							<el-option label="条码" :value="1"></el-option>
							<el-option label="标签" :value="2"></el-option>
						</el-select>
						<span style="font-size: 13px;font-weight: bold">关键字</span>
						<el-autocomplete size="small" style="width: 160px;" class="inline-input" v-model="searchModel" :fetch-suggestions="querySearch" :placeholder="contentHint" @select="handleSelect">
							<el-button id="searchBookData" slot="append" icon="search" @click="searchDatas"></el-button>
						</el-autocomplete>
					</div>
				</div>
			</el-col>
			<el-col :span="12">
				<div style="text-align: right">
					<span style="font-size: 13px;font-weight: bold">{{$t('message.start')}}</span>
					<el-date-picker :editable="false" v-model="startTime" :clearable="false" size="small" type="date" placeholder="选择起始日期" @change="changeStartTime"></el-date-picker>
					<span style="font-size: 13px;font-weight: bold">{{$t('message.end')}}</span>
					<el-date-picker :editable="false" v-model="endTime" :clearable="false" size="small" type="date" placeholder="选择结束日期" @change="changeEndTime"></el-date-picker>
				</div>
			</el-col>
		</el-row>
		<div style="width: 100%">
			<!-- <div style="float: left">
				<span style="font-size: 13px;font-weight: bold">借阅次数排序</span>
				<el-select size="small" v-model="rank" :placeholder="$t('message.selectModeAlert')" style="width: 125px;" @change="selectRank">
					<el-option label="降序" :value="0"></el-option>
					<el-option label="升序" :value="1"></el-option>
				</el-select>
			</div> -->
			<div class="block" style="text-align:right;float: right;padding-bottom: 2px;">
				<el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange" :current-page="currentPage" :page-size="pageSize" :page-sizes="[10,20,30,40,50]" layout="total,sizes, prev, pager, next, jumper" :total="totalSize">
				</el-pagination>
			</div>
		</div>
		<el-table border style="width: 100%;" @selection-change="handleSelectionChange" :data="tableData">
			<el-table-column :show-overflow-tooltip="true" type="selection" align="center" width="50px"></el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="书名" align="center">
				<template slot-scope="scope">
					<a style="color: #50bfff;text-decoration: underline;cursor: pointer" @click="showBookDoubanInfo(scope.row)">{{ scope.row.name }}</a>
				</template>
			</el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="ISBN" align="center" prop="isbn"></el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="条码" align="center" prop="barcode"></el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="标签" align="center" prop="tag"></el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="位置" align="center" prop="position"></el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="关联书架" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.relatedshelf != null">{{scope.row.relatedshelf}}</span>
					<el-tag type="danger" v-else>未关联</el-tag>
				</template>
			</el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="馆藏地" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.location != null">{{scope.row.location}}</span>
					<el-tag v-else type="danger">未绑定</el-tag>
				</template>
			</el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="借阅次数" align="center" prop="borrowcount"></el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="状态" align="center">
				<template slot-scope="scope">
					<el-tag type="danger" v-if="scope.row.status === 1">丢失</el-tag>
					<el-tag type="warning" v-if="scope.row.status === 2">外借</el-tag>
					<el-tag type="success" v-if="scope.row.status === 3">在库</el-tag>
				</template>
			</el-table-column>
			<el-table-column :show-overflow-tooltip="true" align="center" label="操作结果" v-if="showUpdate" width="100">
				<template slot-scope="scope">
					<i v-if="scope.row.update" class="el-icon-loading" style="font-size: 20px"></i>
					<div v-else>
						<el-tag v-if="scope.row.IsUpdated == '1'" type="success">{{content}}成功</el-tag>
						<el-tag v-if="scope.row.IsUpdated == '2'" type="danger">{{scope.row.UpdateMsg}}</el-tag>
					</div>
				</template>
			</el-table-column>
			<el-table-column :show-overflow-tooltip="true" v-if="resultShow" label="剔旧结果" align="center">
				<template slot-scope="scope">
					<el-tag type="success" v-if="scope.row.pickout === 1">剔旧成功</el-tag>
					<el-tag type="danger" v-if="scope.row.pickout === 2">{{scope.row.IsPickOut}}</el-tag>
				</template>
			</el-table-column>
			<el-table-column :show-overflow-tooltip="true" label="位置" align="center">
				<template slot-scope="scope">
					<el-button size="small" type="primary" @click="goBookMap(scope.row)"><i class="el-icon-eleg-icon_pin el-icon--left"></i>查看</el-button>
				</template>
			</el-table-column>
		</el-table>
		<div class="block" style="text-align:right;margin-bottom:100px;padding-top: 3px">
			<el-pagination @current-change="handleCurrentChange" @size-change="handleSizeChange" :current-page="currentPage" :page-size="pageSize" :page-sizes="[10,20,30,40,50]" layout="total,sizes, prev, pager, next, jumper" :total="totalSize">
			</el-pagination>
		</div>
		<!--导入excel-->
		<el-dialog title="导入图书Excel" v-model="importExcelDialog" :class="[dialog-small-width]">
			<div style="width:360px;margin:auto">
				<div style="width: 100%;padding-bottom: 5px">
					<label>馆藏地</label>
					<el-select size="small" v-model="importLocaitionId" :placeholder="$t('message.selectModeAlert')" style="width: 45%;margin-right: 2px">
						<el-option v-for="item in importLocationDatas" :key="item.LocationKeyId" :label="item.Name" :value="item.LocationKeyId">
						</el-option>
					</el-select>
				</div>
				<uploadSection v-if="importExcelDialog" ref="importSection" :band-id="importLocaitionId" :file-type="fileType" :upload-url="uplodaUrl" :accept-types="acceptTypes" v-on:uploadComplete="uploadComplete" :usage="'2'" :control-obj="ControlObj"></uploadSection>
			</div>
		</el-dialog>	
	</div>
</template>
<script>
	import $ from 'jquery'
	import { GloabFun, HttpServer } from '../../../../../assets/js/common.js'
	import headerOpreate from '../../../../../components/headerOpreate'
	import uploadSection from '../../../../../components/import'
	let id = 1000;
	var date = new Date();
	export default {
		components: {
			headerOpreate,
			uploadSection
		},
		data() {
			//回车触发查询按钮
			document.onkeydown = function(event) {
				var e = event || window.event;
				if(e && e.keyCode == 13) { //回车键的键值为13
					$("#searchBookData").click(); //调用登录按钮的登录事件
				}
			};
			Date.prototype.format = function(format) {
				var date = {
					"M+": this.getMonth() + 1,
					"d+": this.getDate()
				};
				if(/(y+)/i.test(format)) {
					format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
				}
				for(var k in date) {
					if(new RegExp("(" + k + ")").test(format)) {
						format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
							date[k] : ("00" + date[k]).substr(("" + date[k]).length));
					}
				}
				return format;
			}
			return {
				flag: false,//馆藏地下拉框标示位
				flag2: false,//排序下拉框标示位
				isReload: false,
				importExcelDialog: false,
				importLocaitionId: 0,
				importLocationDatas: [],
				importForm: {},
				uplodaUrl: '/Api/User/File/ExcelImport',
				acceptTypes: 'xls,xlsx',
				ControlObj: {},
				fileType: 2,
				location: null,
				locationDatas: [],
				isbns: [], //更新豆瓣信息时需要的数组
				searchHistory: [],
				item: {},
				value: 0,
				contentHint: '书名/作者 查询',
				searchModel: '',
				startTime: new Date((date.getTime() - 3600 * 1000 * 24 * 30)).format('yyyy-MM-dd') + ' 00:00:00',
				endTime: date.format('yyyy-MM-dd') + ' 23:59:59',
				rank: 0,
				tableData: [],
				content: '',
				multipleSelection: [],
				currentPage: 1,
				pageSize: 10,
				totalSize: 0,
				showUpdate: false,
				resultShow: false,
				loading: false,
				IsShow: GloabFun.getUid() == 'admin' ? true : false,
				opreateDatas: [{
					size: "small",
					type: 'primary',
					icon: 'el-icon-eleg-icon_refresh el-icon--left',
					name: '刷新',
					action: 'reloadDatas'
				},
				{
					size: "small",
					type: 'primary',
					icon: 'el-icon-eleg-icon_folder_download el-icon--left',
					name: '下载模板',
					action: 'downloadExcel'
				},
				{
					size: "small",
					type: 'primary',
					icon: 'el-icon-eleg-icon_folder_upload el-icon--left',
					name: '导入',
					action: 'importExcel'
				},
				{
					size: "small",
					type: 'primary',
					icon: 'el-icon-eleg-icon_blocked el-icon--left',
					name: '图书去重',
					action: 'deleteBadInfo'
				},
				{
					size: "small",
					type: "danger",
					icon: "el-icon-delete2 el-icon--left",
					name: "删除",
					action: "multipleDeleteBook"
				}
				]
			}
		},
		props: {
			templateObj: {
				type: Object,
				default: function() {
					return {};
				}
			}
		},
		methods: {
			executeAction(action) {
				if(action) {
					this[action]();
				}
			},
			//图书去重
			deleteBadInfo() {
				var row = {};
				row.value = this.value;
				row.location = this.location;
				row.searchModel = this.searchModel;
				row.currentPage = this.currentPage;
				row.pageSize = this.pageSize;
				row.rank = this.rank;
				row.startTime = this.startTime;
				row.endTime = this.endTime;
				this.$emit('changeView', 'deleteBad', row);
			},
			//导出表格
			exportExcel() {　　　　　　
				require.ensure([], () => {　　　　　　　　
					const {
						export_json_to_excel
					} = require('../../../../../assets/js/vendor/Export2Excel.js');　　　　　　　　
					const tHeader = ['ISBN', '图书条码', '图书标签', '书名', '作者', '出版社', '类型', '位置', '借阅次数', '上架时间', '备注'];　　　　　　　　
					const filterVal = ['isbn', 'barcode', 'tag', 'name', 'author', 'press', 'type','position', 'borrowcount', 'bindtime', 'bookStatus'];　　　　　　　　
					const list = this.tableData;　　　　　　　　
					const data = this.formatJson(filterVal, list);　
					var beginTime = new Date(this.startTime).format('yyyy-MM-dd');
					var overTime = new Date(this.endTime).format('yyyy-MM-dd');　　　　　　　
					export_json_to_excel(tHeader, data, beginTime + '至' + overTime + '图书信息');　　　　　　
				})　　　
			},
			exportAll() {
				var param = {
					barcode: this.value === 1 ? this.searchModel : '',
					tag: this.value === 2 ? this.searchModel : '',
					keyword: this.value === 0 ? this.searchModel : '',
					queryid: this.location,
					index: 0,
					pagesize: 0,
					order: this.rank,
					begin: this.startTime,
					end: this.endTime
				}
				HttpServer.httpPost.call(this, '/Api/Book/Info', param, function(response) {}, function(response) {
					if(response.data.code === 0) {
						response.data.info.forEach(function(item) {
							if(item.status === 1) {
								item.bookStatus = '丢失';
							} else if(item.status === 2) {
								item.bookStatus = '外借';
							} else {
								item.bookStatus = '在库';
							}
						})
						require.ensure([], () => {　　　　　　　　
							const {
								export_json_to_excel
							} = require('../../../../../assets/js/vendor/Export2Excel.js');　　　　　　　　
							const tHeader = ['ISBN', '图书条码', '图书标签', '书名', '作者', '出版社', '类型', '位置', '借阅次数', '上架时间', '备注'];　　　　　　　　
							const filterVal = ['isbn', 'barcode', 'tag', 'name', 'author', 'press', 'type','position', 'borrowcount', 'bindtime', 'bookStatus'];　　　　　　　　　
							const list = response.data.info;　　　　　　　　
							const data = this.formatJson(filterVal, list);　
							var beginTime = new Date(this.startTime).format('yyyy-MM-dd');
							var overTime = new Date(this.endTime).format('yyyy-MM-dd');　　　　　　　
							export_json_to_excel(tHeader, data, beginTime + '至' + overTime + '图书信息');　　
						})
					} else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
				});	
			},
			formatJson(filterVal, jsonData) {　　　　　　
				return jsonData.map(v => filterVal.map(j => v[j]))　　
			},		
			//下载excel模板
			downloadExcel() {
				window.location.href = localHost + '/Api/User/File/Download/ExcelFile?uid=' + GloabFun.getUid() + '&token=' + GloabFun.getToken() + '&filetype=2';
			},
			sortDatas(arr) {
				for(var i=0;i<arr.length;i++){
					for(var j = i + 1;j<arr.length;j++){
						if(arr[i].DistrictKeyId>arr[j].DistrictKeyId){
							var tmp = arr[i];
							arr[i] = arr[j];
							arr[j] = tmp;
						}
					}
				}
				return arr;
			},

			//导入excel表格弹窗查询馆藏地
			getLocationInImportDialog() {
				HttpServer.httpPost.call(this,'/Api/LibraryLocation/GetByUser',{UserId: parseInt(GloabFun.getKeyId())},function(response){},function(response){
					if(response.data.code === 0){
						this.importLocationDatas = response.data.info;
						this.importLocaitionId = this.importLocationDatas[0].LocationKeyId;
						this.importExcelDialog = true;
					}else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
				})
			},
			//导入excel
			importExcel() {
				this.getLocationInImportDialog();
			},
			uploadComplete() {
				this.$notify({
					title: '成功',
					message: this.$t('message.uploadSuccess'),
					type: 'success',
					duration: 2500
				});
			},
			querySearch(queryString, cb) {
				var restaurants = this.searchHistory;
				var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants;
				// 调用 callback 返回建议列表的数据
				cb(results);
			},
			createFilter(queryString) {
				return(restaurant) => {
					return(restaurant.value.indexOf(queryString.toLowerCase()) === 0);
				};
			},
			handleSelect(item) {
			},
			//导出表格
			handleExportExcel(command) {
				if(command === '1'){
					this.exportExcel();
				}else {
					this.exportAll();
				}
			},
			// 更多操作
			handleCommand(command) {
				if(command === '1') {
					this.multipleUpdateBook();
				} else if(command === '2') {
					this.multipleUpdateDouBanInfo();
				} else if(command === '3') {
					this.pickoutList();
				}else if(command === '4'){
					this.pickout();
				}
			},
			changeStartTime() {
				this.startTime = new Date(this.startTime).format('yyyy-MM-dd') + ' 00:00:00';
				this.searchDatas();
			},
			changeEndTime() {
				this.endTime = new Date(this.endTime).format('yyyy-MM-dd') + ' 23:59:59';
				this.searchDatas();
			},
			handleCurrentChange(val) {
				this.currentPage = val;
				this.searchDatas();
			},
			handleSizeChange(val) {
				this.pageSize = val;
				this.searchDatas();
			},
			//选择升序降序
			selectRank() {
				this.searchDatas();
				// this.flag2 ? this.searchDatas() : this.flag2 = true;
			},
			selectLocation() {
				this.flag ? this.searchDatas() : this.flag = true;
			},
			//选择查询类型
			selectType() {
				if(this.value === 0) {
					this.contentHint = '书名/作者 查询';
				} else if(this.value === 1) {
					this.contentHint = '请输入完整的图书条码';
				} else {
					this.contentHint = '请输入完整的图书标签';
				}
			},
			handleSelectionChange(val) {
				this.multipleSelection = val;
			},
			formateSelection() {
				var result = [],
				array = this.multipleSelection;
				for(var i = 0; i < array.length; i++) {
					result.push(array[i]);
				}
				return result;
			},
			//查看图书豆瓣信息
			showBookDoubanInfo(row) {
				row.value = this.value;
				row.location = this.location;
				row.searchModel = this.searchModel;
				row.currentPage = this.currentPage;
				row.pageSize = this.pageSize;
				row.rank = this.rank;
				row.startTime = this.startTime;
				row.endTime = this.endTime;
				this.$emit('changeView', 'DouBanInfo', row);
			},
			goBookMap(row) {
				row.value = this.value;
				row.location = this.location;
				row.searchModel = this.searchModel;
				row.currentPage = this.currentPage;
				row.pageSize = this.pageSize;
				row.rank = this.rank;
				row.startTime = this.startTime;
				row.endTime = this.endTime;
				this.$emit('changeView', 'bookMap', row);
			},
			//批量同步图书状态
			multipleUpdateBook() {
				if(this.formateSelection().length > 0) {
					this.$confirm('此操作将同步所选图书状态，是否继续?', '提示', {
						confirmButtonText: this.$t('message.yes'),
						cancelButtonText: this.$t('message.no'),
						type: 'warning'
					}).then(() => {
						this.showUpdate = true;
						var result = [];
						for(var i = 0; i < this.formateSelection().length; i++) {
							result.push(this.formateSelection()[i].barcode);
							for(var j = 0; j < this.tableData.length; j++) {
								if(this.formateSelection()[i].barcode == this.tableData[j].barcode) {
									this.tableData[j].update = true;
								}
							}
						}
						var param = {
							barcode: result
						}
						HttpServer.httpPost.call(this, '/Api/Book/Update', param, function(response) {}, function(response) {
							this.content = '同步';
							if(response.data.code === 0) {
								for(var i = 0; i < response.data.info.length; i++) {
									for(var j = 0; j < this.tableData.length; j++) {
										if(this.tableData[j].barcode == response.data.info[i].barcode) {
											this.tableData[j].update = false;
											if(response.data.info[i].code === 0) {
												this.tableData[j].IsUpdated = '1';
											} else {
												this.tableData[j].IsUpdated = '2';
												this.tableData[j].UpdateMsg = '同步失败';
											}
										}
									}
								}
							} else {
								this.$notify.error({
									title: '错误',
									message: response.data.msg,
									duration: 2500
								});
							}
						});
					}).catch(() => {
						this.$notify.info({
							title: '消息',
							message: this.$t('message.operationCanceled'),
							duration: 2500
						})
					});
				} else {
					this.$notify({
						title: this.$t('message.warning'),
						message: '请选择要批量同步的项',
						type: 'warning',
						duration: 2500
					});
				}
			},
			//批量更新豆瓣信息
			multipleUpdateDouBanInfo() {
				let vm = this;
				if(this.formateSelection().length > 0) {
					this.$confirm('此操作将更新所选图书信息，是否继续?', '提示', {
						confirmButtonText: this.$t('message.yes'),
						cancelButtonText: this.$t('message.no'),
						type: 'warning'
					}).then(() => {
						this.showUpdate = true;
						this.isbns.splice(0, this.isbns.length);
						for(var i = 0; i < this.formateSelection().length; i++) {
							for(var j = 0; j < this.tableData.length; j++) {
								if(this.formateSelection()[i].isbn == this.tableData[j].isbn) {
									this.tableData[j].update = true;
									this.isbns.push(this.formateSelection()[i].isbn);
								}
							}
						}
						HttpServer.httpPost.call(this, '/Api/Book/Update/Douban', {
							isbn: this.isbns
						}, function(response) {}, function(response) {
							this.content = '更新';
							// this.updateDouBanLoading = false;
							if(response.data.code === 0) {
								for(var i = 0; i < response.data.info.length; i++) {
									for(var j = 0; j < this.tableData.length; j++) {
										if(this.tableData[j].isbn == response.data.info[i].isbn) {
											this.tableData[j].update = false;
											if(response.data.info[i].code === 0) {
												this.tableData[j].IsUpdated = '1';
											} else {
												this.tableData[j].IsUpdated = '2';
												this.tableData[j].UpdateMsg = response.data.info[i].msg;
											}
										}
									}
								}
							} else {
								this.$notify.error({
									title: '错误',
									message: response.data.msg,
									duration: 2500
								});
							}
						});
					}).catch(() => {
						this.$notify.info({
							title: '消息',
							message: this.$t('message.operationCanceled'),
							duration: 2500
						})
					});
				} else {
					this.$confirm('未选择图书，将更新所有图书信息，是否继续?', '提示', {
						confirmButtonText: this.$t('message.yes'),
						cancelButtonText: this.$t('message.no'),
						type: 'warning'
					}).then(() => {
						HttpServer.httpPost.call(this, '/Api/Book/Update/Douban/All', {}, function(response) {}, function(response) {
							if(response.data.code === 0) {
								this.$notify({
									title: '成功',
									message: this.$t('message.updateSuccess'),
									type: 'success',
									duration: 2500
								});
							} else {
								this.$notify.error({
									title: '错误',
									message: response.data.msg,
									duration: 2500
								});
							}
						});
					}).catch(() => {
						this.$notify.info({
							title: '消息',
							message: this.$t('message.operationCanceled'),
							duration: 2500
						})
					});
				}
			},
			//前往剔旧列表页面
			pickoutList() {
				this.$emit('changeView', 'Pickout', {});
			},
			//批量替旧
			pickout() {
				let vm = this;
				if(this.formateSelection().length > 0) {
					this.$confirm('此操作将对所选图书进行剔旧处理，是否继续?', '提示', {
						confirmButtonText: '确定',
						cancelButtonText: '取消',
						type: 'warning'
					}).then(() => {
						var result = [];
						for(var i = 0; i < this.formateSelection().length; i++) {
							result.push(this.formateSelection()[i].keyid);
						}
						HttpServer.httpPost.call(this, '/Api/PickOut/Add', {
							bookid: result
						}, function(response) {}, function(response) {
							// console.log('resultShow',response)
							this.resultShow = true;
							response.data.info.forEach(function(result) {
								vm.tableData.forEach(function(item) {
									// console.log(item)
									if(item.barcode === result.bookcode) {
										if(result.code === 0) {
											item.pickout = 1;
											item.IsPickOut = '剔旧成功';
										} else {
											item.pickout = 2;
											item.IsPickOut = result.msg;
										}
									}
								})
							})
						})
					}).catch(() => {
						this.$notify.info({
							title: '消息',
							message: this.$t('message.operationCanceled'),
							duration: 2500
						})
					});
				} else {
					this.$notify({
						title: this.$t('message.warning'),
						message: '请选择批量操作的项',
						type: 'warning',
						duration: 2500
					});
				}
			},
			//批量删除图书信息
			multipleDeleteBook() {
				// console.log('this.formateSelection()',this.formateSelection());
				if(this.formateSelection().length > 0) {
					this.$confirm('此操作将删除图书信息，是否继续?', '提示', {
						confirmButtonText: this.$t('message.yes'),
						cancelButtonText: this.$t('message.no'),
						type: 'warning'
					}).then(() => {
						var result = [];
						for(var i = 0; i < this.formateSelection().length; i++) {
							result.push(this.formateSelection()[i].keyid);
						}
						var param = {
							keyid: result
						}
						HttpServer.httpPost.call(this, '/Api/Book/Delete', param, function(response) {}, function(response) {
							if(response.data.code === 0) {
								this.searchDatas();
								this.$notify({
									title: '成功',
									message: this.$t('message.bulkDeleteSuccess'),
									type: 'success',
									duration: 2500
								});
							} else {
								this.searchDatas();
								this.$notify.error({
									title: '错误',
									message: response.data.msg,
									duration: 2500
								});
							}
						});
					}).catch(() => {
						this.$notify.info({
							title: '消息',
							message: this.$t('message.operationCanceled'),
							duration: 2500
						})
					});
				} else {
					this.$notify({
						title: this.$t('message.warning'),
						message: this.$t('message.selectBulkDeleteWarning'),
						type: 'warning',
						duration: 2500
					});
				}
			},
			formateDate(array) {
				for(var i = 0; i < array.length; i++) {
					var index1 = array[i].bindtime.indexOf("T");
					array[i].bindtime = array[i].bindtime.substring(0, index1) + " " + array[i].bindtime.substring(index1 + 1, index1 + 9);
				}
			},
			//刷新
			reloadDatas() {
				this.isReload = true;
				this.searchDatas();
			},
			//用于搜索与刷新的方法
			searchDatas() {
				this.loading = true;
				this.showUpdate = false;
				this.resultShow = false;
				//保存至搜索历史
				if(this.searchModel != '') {
					this.item.value = this.searchModel;
					if(JSON.stringify(this.searchHistory).indexOf(JSON.stringify(this.item)) == -1) {
						if(this.searchHistory.length === 7) {
							this.searchHistory.splice(0, 1);
						}
						this.searchHistory.push(this.item);
						GloabFun.setSearchBook(JSON.stringify(this.searchHistory));
						this.$nextTick(function() {
							this.searchHistory = JSON.parse(GloabFun.getSearchBook());
						})
					}
				}
				var param = {
					barcode: this.value === 1 ? this.searchModel : '',
					tag: this.value === 2 ? this.searchModel : '',
					keyword: this.value === 0 ? this.searchModel : '',
					queryid: this.location,
					index: this.currentPage,
					pagesize: this.pageSize,
					order: this.rank,
					begin: this.startTime,
					end: this.endTime
				}
				HttpServer.httpPost.call(this, '/Api/Book/Info', param, function(response) {}, function(response) {
					this.loading = false;
					if(response.data.code === 0) {
						// this.formateDate(response.data.info);
						response.data.info.forEach(function(item) {
							item.update = false;
							item.IsUpdated = '';
							item.pickout = 0;
							item.IsPickOut = '';
							if(item.status === 1) {
								item.bookStatus = '丢失';
							} else if(item.status === 2) {
								item.bookStatus = '外借';
							} else {
								item.bookStatus = '在库';
							}
						})
						this.tableData = response.data.info;
						this.totalSize = response.data.totalcount;

						if(window.localStorage){
							//保存到localStorage
							localStorage.setItem('bookDatas',JSON.stringify({
								data: this.tableData,
								total: this.totalSize,
								index: this.currentPage,
								size: this.pageSize,
								location: this.location,
								value: this.value,
								searchModel: this.searchModel,
								rank :this.rank,
								startTime :this.startTime,
								endTime :this.endTime})
							);
						}else{
							console.log('This browser does NOT support localStorage')
						}

						if(this.isReload){
							this.$notify({
								title: '成功',
								message: this.$t('message.refreshSuccess'),
								type: 'success',
								duration: 2500
							});
						}
					} else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
					this.isReload = false;
				});	
			},
			//查询
			getDatas() {
				//查询本地是否存在读者的本地缓存数据
				if(localStorage.getItem('bookDatas') != null){
					this.tableData = JSON.parse(localStorage.getItem('bookDatas')).data;
					this.totalSize = JSON.parse(localStorage.getItem('bookDatas')).total;
					this.currentPage = JSON.parse(localStorage.getItem('bookDatas')).index;
					this.pageSize = JSON.parse(localStorage.getItem('bookDatas')).size;
					this.location = JSON.parse(localStorage.getItem('bookDatas')).location;
					this.value = JSON.parse(localStorage.getItem('bookDatas')).value;
					this.searchModel = JSON.parse(localStorage.getItem('bookDatas')).searchModel;
					this.rank = JSON.parse(localStorage.getItem('bookDatas')).rank;
					this.startTime = JSON.parse(localStorage.getItem('bookDatas')).startTime;
					this.endTime = JSON.parse(localStorage.getItem('bookDatas')).endTime;
				}else {
					this.loading = true;
					this.showUpdate = false;
					this.resultShow = false;
					var param = {
						barcode: this.value === 1 ? this.searchModel : '',
						tag: this.value === 2 ? this.searchModel : '',
						keyword: this.value === 0 ? this.searchModel : '',
						queryid: this.location,
						index: this.currentPage,
						pagesize: this.pageSize,
						order: this.rank,
						begin: this.startTime,
						end: this.endTime
					}
					HttpServer.httpPost.call(this, '/Api/Book/Info', param, function(response) {}, function(response) {
						this.loading = false;
						if(response.data.code === 0) {
							// this.formateDate(response.data.info);
							response.data.info.forEach(function(item) {
								item.update = false;
								item.IsUpdated = '';
								item.pickout = 0;
								item.IsPickOut = '';
								if(item.status === 1) {
									item.bookStatus = '丢失';
								} else if(item.status === 2) {
									item.bookStatus = '外借';
								} else {
									item.bookStatus = '在库';
								}
							})
							this.tableData = response.data.info;
							this.totalSize = response.data.totalcount;

							if(window.localStorage){
								//保存到localStorage
								localStorage.setItem('bookDatas',JSON.stringify({
									data: this.tableData,
									total: this.totalSize,
									index: this.currentPage,
									size: this.pageSize,
									location: this.location,
									value: this.value,
									searchModel: this.searchModel,
									rank :this.rank,
									startTime :this.startTime,
									endTime :this.endTime})
								);
							}else{
								console.log('This browser does NOT support localStorage')
							}
						} else {
							this.$notify.error({
								title: '错误',
								message: response.data.msg,
								duration: 2500
							});
						}
					});	
				}
			},
			//查询用户绑定的馆藏地
			getLocationDatasByUser() {
				HttpServer.httpPost.call(this,'/Api/LibraryLocation/GetByUser',{UserId: parseInt(GloabFun.getKeyId())},function(response){},function(response){
					if(response.data.code === 0){
						response.data.info.unshift(
						{
							Name: '全部',
							LocationKeyId: 0
						}						
						);
						this.locationDatas = response.data.info;
						if(this.templateObj.currentPage){
							this.location = this.templateObj.location;
						}else {
							this.location = this.locationDatas[0].LocationKeyId;
						}
						this.getDatas();
					}else {
						this.$notify.error({
							title: '错误',
							message: response.data.msg,
							duration: 2500
						});
					}
				})
			}
		},
		created() {
			var str = GloabFun.getSearchBook();
			if(str != '') {
				this.searchHistory = JSON.parse(str);
			} else {
				this.searchHistory = [];
			}
			if(this.templateObj.searchModel) {
				this.searchModel = this.templateObj.searchModel;
				this.value = this.templateObj.value;
			}
			if(this.templateObj.currentPage) {
				this.currentPage = this.templateObj.currentPage;
				this.pageSize = this.templateObj.pageSize;
				this.location = this.templateObj.selectLocation;
				this.rank = this.templateObj.rank;
				this.startTime = this.templateObj.startTime;
				this.endTime = this.templateObj.endTime;
			}
			this.getLocationDatasByUser();
		}
	}
</script>
<style scoped lang="less">
	.el-date-editor.el-input {
		width: 120px;
	}
	
	.flex-inline {
		display: flex;
		justify-content: space-between;
	}
	
	.query {
		display: flex;
	}
	
	.name {
		color: #20a0ff;
	}
	
	.edit-mission {
		padding-top: 50px;
		.el-dialog__header {
			background-color: #000;
		}
		.el-dialog__body {
			position: relative;
		}
		.clearfloat {
			height: 100px;
			max-height: 150px;
		}
	}
</style>